#ifndef MDX2_ANIMATION_H_
#define MDX2_ANIMATION_H_

#include <cstdint>
#include "Vector3D.h"

// Interpolation types
#define INTERPOLATION_NONE          0
#define INTERPOLATION_LINEAR        1
#define INTERPOLATION_HERMITE       2
#define INTERPOLATION_BEZIER        3

// Flags
#define FL_ANIM_LOOP                0x20

// Keybones
static const char* KEYBONES[] =
{
    "ArmL",
    "ArmR",
    "ShoulderL",
    "ShoulderR",
    "SpineLow",
    "Waist",
    "Head",
    "Jaw",
    "IndexFingerR",
    "MiddleFingerR",
    "PinkyFingerR",
    "RingFingerR",
    "ThumbR",
    "IndexFingerL",
    "MiddleFingerL",
    "PinkyFingerL",
    "RingFingerL",
    "ThumbL",
    "$BTH",
    "$CSR",
    "$CSL",
    "_Breath",
    "_Name",
    "_NameMount",
    "$CHD",
    "$CCH",
    "Root",
    "Wheel1",
    "Wheel2",
    "Wheel3",
    "Wheel4",
    "Wheel5",
    "Wheel6",
    "Wheel7",
    "Wheel8"
};

// Description: Referencing animation data
struct MDX2_ABlock
{
    int16_t Interpolation;
    int16_t GlobalSequence;
#if MDX_BUILD < 28
    uint32_t nRanges;
    uint32_t ofsRanges;
#endif
    uint32_t nTimestamps;
    uint32_t ofsTimestamps;
    uint32_t nValues;
    uint32_t ofsValues;
};

// Description: Like MDX2_ABlock, without interpolation
//              and global sequence.
struct MDX2_FBlock
{
#if MDX_BUILD < 28
    uint32_t nRanges;
    uint32_t ofsRanges;
#endif
    uint32_t nTimestamps;
    uint32_t ofsTimestamps;
    uint32_t nValues;
    uint32_t ofsValues;
};

#if MDX_BUILD >= 28
// Timestamp/data offset and count (represents a timeline)
struct MDX2_CountOffsetPair
{
    uint32_t Count;
    uint32_t Offset;
};
#endif

// Decription: Animation sequence information.
//             They are indexed in the lookup table with the
//             corresponding index in AnimationData.dbc.
// Count:  MDX2_Header->nAnimations
// Offset: MDX2_Header->ofsAnimations;
// Lookup: AnimationLookup
struct MDX2_Sequence
{
#if MDX_BUILD < 28
    uint32_t ID;
    uint32_t Timestamp[2];
#elif MDX_BUILD >= 28
    uint16_t ID;
    uint16_t SubID;
    uint32_t Length;
#endif
    float MovingSpeed;
    uint32_t Flags;
    int16_t Probability;
    int16_t Unused;
    uint32_t Unknown1;
    uint32_t Unknown2;
    Vec3F MinExtents[2];
    Vec3F MaxExtents[2];
    float Radius;
    int16_t NextAnimation;
    int16_t Index;
};

// Description: Bone structure.
//              Indexed by the keybone ID in the keybone lookup.
// Count:  MDX2_Header->nBones
// Offset: MDX2_Header->ofsBones
// Lookup: BoneLookup, KeyBoneLookup
struct MDX2_Bone
{
    int32_t KeyBone;
    uint32_t Flags;
    int16_t ParentBone;
    uint16_t Unknown1;
#if MDX_BUILD >= 24
    uint16_t Unknown2;
    uint16_t Unknown3;
#endif
    MDX2_ABlock Translation;
    MDX2_ABlock Rotation;
    MDX2_ABlock Scaling;
    Vec3F PivotPoint;
};

#endif // MDX2_ANIMATION_H_